package org.putrpctorest.container.impl;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.cxf.helpers.DOMUtils;
import org.putrpctorest.PutRpcToRestError;
import org.putrpctorest.container.Container;
import org.putrpctorest.expression.RestMethodEntryPoint;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class ContainerImpl implements Container {

    // private Services serviceDefinitions;
    // private ServiceInvoker serviceInvoker;
    private Class<?> serviceClass;

    ContainerImpl(String restServiceDefinitionsPath, String serviceExpressions) {
        // serviceDefinitions = ResourcesParser
        // .parse(parseXML(restServiceDefinitionsPath));
        //
        // serviceInvoker = new ServiceInvokerImpl(this);
        //
        // ServiceClassGenerator serviceClassGenerator = new JavassistServiceClassGenerator();
        //
        // serviceClass = serviceClassGenerator
        // .generateClass(serviceDefinitions);
    }

    // @Override
    // public Services getServices() {
    // return serviceDefinitions;
    // }
    //
    // @Override
    // public ServiceInvoker getServiceInvoker() {
    // return serviceInvoker;
    // }

    @Override
    public Class<?> getServiceClass() {
        return serviceClass;
    }

    @Override
    public RestMethodEntryPoint getRestMethodEntryPoint(String entryPointName) {
        // TODO Auto-generated method stub
        return null;
    }

    private Element parseXML(String path) {
        InputStream is;
        try {
            is = new FileInputStream(path);
            Document doc = DOMUtils.readXml(new InputStreamReader(is, "UTF-8"));
            return doc.getDocumentElement();
        } catch (Exception e) {
            throw new PutRpcToRestError("Erro parsing xml file:" + path + ". " + e, e);
        }
    }

    @Override
    public Object getServiceObject() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getId() {

        // TODO Auto-generated method stub
        return null;
    }

}
